﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Collections;


namespace frm_medic
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void btn_ok_Click(object sender, EventArgs e)
        {
            
            string conStr = "Data Source=DESKTOP-CM2RP4R;Initial Catalog=medic;Integrated Security=SSPI";
            SqlConnection con = new SqlConnection(conStr);
            
            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = "select * from Us";
                cmd.Connection = con;
                SqlDataReader reader = cmd.ExecuteReader();
            if(reader.Read())
            {
                
                string pasw = reader["pasw"].ToString();
                if (pasw.Trim() == textBox1.Text.Trim())
                {

                    
                    Form2 f2 = new Form2();
                    f2.Show();
                    this.Hide();
                    
                }
                else
                {
                    MessageBox.Show("密码错误，请重新输入");
                    textBox1.Text = "";
                }

            }
            reader.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            finally
            {
                
                con.Close();
                
            }

        }



        private void btn_cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            ArrayList list = new ArrayList();
            string sql = "select Us from Us";
            string conStr = "Data Source=DESKTOP-CM2RP4R;Initial Catalog=medic;Integrated Security=SSPI";
            SqlConnection con = new SqlConnection(conStr);
            try
            {
                con.Open();
               
                SqlDataAdapter da = new SqlDataAdapter(sql, con);
                DataSet ds = new DataSet();
                da.Fill(ds);
                DataTable dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                list.Add(dr[0].ToString().Trim());
                 }
            comboBox1.DataSource = list;
            }


            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            finally
            {
                con.Close();
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            
        }

    }
   
}
